package com.zone.demo.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zone.demo.dto.Account;
import com.zone.demo.dto.User;
import com.zone.demo.service.UserService;
import com.zone.demo.util.JsonResult;
import com.zone.demo.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
* Description
* @author nixin
* @date 2021/7/8 21:36
* @param 
* @return 
*/
@RestController
public class UserController {

   private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }
    @GetMapping(value = "/getAmountByName")
    public JsonResult getAmountByName(String name) {
       Account account = this.userService.getAmountByName(name);
       return new JsonResult(ResultCode.SUCCESS, account);
    }
    @GetMapping(value = "/createTableUser")
    public JsonResult createTableUser() {
        this.userService.createTableUser();
        return new JsonResult(ResultCode.SUCCESS);
    }

    @GetMapping(value = "/insertDataToUser")
    public JsonResult insertDataToUser(int current,int limit) {
        this.userService.insertDataToUser();
        IPage<User> user = this.userService.getAllUser(current,limit);
        return new JsonResult(ResultCode.SUCCESS, user);
    }
    @GetMapping(value = "/createTableAccount")
    public JsonResult createTableAccount() {
        this.userService.createTableAccount();
        return new JsonResult(ResultCode.SUCCESS);
    }

    @GetMapping(value = "/insertDataToAccount")
    public JsonResult insertDataToAccount(int current,int limit) {
        this.userService.insertDataToAccount();
        IPage<Account> account = this.userService.getAllAccount(current,limit);
        return new JsonResult(ResultCode.SUCCESS, account);

    }
}
